package arch.dao.impl.archive;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.springframework.jdbc.core.RowMapper;

import arch.domain.archive.Template;

public class TemplateMapper implements RowMapper  {
	boolean content = false;
	boolean image = false;
	public TemplateMapper(boolean ar_content,boolean ar_image){
		this.content = ar_content;
		this.image =  ar_image;
	}

	public Object mapRow(ResultSet rs, int i) throws SQLException {
		Template temp = new Template();
		if(rs.getObject("id")!=null){
			temp.setId((Integer)rs.getObject("id"));
		}		
		temp.setName(rs.getString("name"));
		temp.setRank(rs.getInt("rank"));
		temp.setVersion(rs.getInt("version"));	
		if(content==true){
			temp.setContent(rs.getBytes("content"));
		}
		if(image==true){
			temp.setThumbnail(rs.getBytes("thumbnail"));
		}
		temp.setCreateTime(new Date(rs.getDate("create_time").getTime()));
		temp.setLastUpdateTime(new Date(rs.getDate("last_update_time").getTime()));
		temp.setDescription(rs.getString("description"));
		return temp;
	}

}
